package com.hnkywl.sts.service.base;

import com.hnkywl.sts.dao.base.FjDao;
import com.hnkywl.sts.entity.base.Fj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-4-3
 * Time: 下午6:44
 * To change this template use File | Settings | File Templates.
 */
@Service
public class FjService {
    private FjDao fjDao;

    @Transactional
    public Fj getFj(Long  fjId) {
        return fjDao.get(fjId);
    }

    @Transactional
    public void saveFj(Fj fj) {
        fjDao.save(fj);
    }

    @Transactional
    public void deleteFj(Long id) {
        try {
            Fj fj = this.fjDao.get(id);
            if (fj != null) {
                File file = new File(fj.getWjlj());
                // 判断目录或文件是否存在
                if (file.exists()) {
                    // 判断是否为文件
                    if (file.isFile()) {
                        file.delete();
                    }
                }
                this.fjDao.delete(fj);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    @Autowired
    public void setFjDao(FjDao fjDao) {
        this.fjDao = fjDao;
    }
}
